package com.cby.operation.pay.channel.wechat

import android.app.Activity
import android.content.Intent
import android.net.Uri
import com.cby.operation.pay.bean.PayOrderInfo
import com.cby.operation.pay.channel.PayResultCallBack
import com.cby.operation.pay.channel.PayWrapper
import com.cby.operation.sdk.ERR_MSG_SDK_ACTIVITY_IS_NULL

/**
 * 描述信息:微信支付包装类
 *
 * @author xuzhiwei
 * @create 2020/8/3
 */
class WechatPayWrapper : PayWrapper {
    override fun doPay(
        activity: Activity?,
        orderInfo: PayOrderInfo?,
        callBack: PayResultCallBack?
    ) {
        //Uri uri = Uri.parse("weixin://wap/pay?prepayid%3Dwx021710254123411d05c0ae7f1701735900&package=2134161975&noncestr=1577956225&sign=55839cd3b859f37f9b84a0c857dbe57a");
        val uri = Uri.parse(orderInfo!!.payParams!!.url)
        val intent = Intent(Intent.ACTION_VIEW, uri)
        if (activity == null) {
            //Activity currentActivity = HykbAntiManager.getInstance().getCurrentActivity();
            //currentActivity.startActivity(intent);
            callBack!!.onResult(false, "", ERR_MSG_SDK_ACTIVITY_IS_NULL)
            return
        } else {
            activity.startActivity(intent)
        }
        callBack!!.onResult(false, HYKB_WECHATH5_CODE_SUBMIT, HYKB_WECHATH5_MSG_SUBMIT)
    }

    companion object {
        /** 订单已提交  */
        const val HYKB_WECHATH5_CODE_SUBMIT = "9001"
        const val HYKB_WECHATH5_MSG_SUBMIT = "订单已提交，等待处理中"
    }
}